package com.shengyuan.manage_os.ui;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.os.Handler;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;


import com.android.volley.Request;
import com.shengyuan.manage_os.R;
import com.shengyuan.manage_os.bean.NetURL;
import com.shengyuan.manage_os.im.common.utils.NetUtils;
import com.shengyuan.manage_os.im.ui.SDKCoreHelper;
import com.shengyuan.manage_os.intface.NetResponses;
import com.shengyuan.manage_os.json.JsonUtils;
import com.shengyuan.manage_os.old.ying.boce.task.TaskParams;
import com.shengyuan.manage_os.old.ying.erpm.LoginActivity;
import com.shengyuan.manage_os.old.ying.erpm.util.SharePreferenceUtil;
import com.shengyuan.manage_os.sqlite.SQLiteTools;
import com.shengyuan.manage_os.utils.DownloadAPK;
import com.shengyuan.manage_os.utils.EquipParam;
import com.shengyuan.manage_os.old.ying.erpm.tasks.LoginTask;
import com.shengyuan.manage_os.utils.NetRequest;
import com.yuntongxun.ecsdk.platformtools.ECHandlerHelper;

import org.apache.http.HttpRequest;
import org.json.JSONObject;

import java.util.List;

import oa.database.bean.Department;

public class WelComeActivity extends Activity implements NetResponses {

    private boolean isFirstIn = true;
    private SharedPreferences sp;
    public boolean isNetworkEnable;
    private SharePreferenceUtil util;
    private NetRequest netRequest = null;

    private Runnable initRunnable = new Runnable() {
        @Override
        public void run() {
            String d = android.os.Build.MODEL;

//            if("".equals(util.getId()) || "".equals(util.getName())){
//                Intent intent1 = new Intent(WelComeActivity.this,LoginActivity.class);
//                startActivity(intent1);
//            }
            if (isFirstIn){
                setContentView(R.layout.form_login);
            }

        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //设置全屏
//        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_welcome);
        netRequest = new NetRequest(getApplication());
        netRequest.setNetResponses(this);
//        if (NetUtils.isOpenNetwork(this)){
//            netRequest.request(Request.Method.GET, NetURL.CHECK_APK_VERSION, null, "", "CONTACT", 100);
//        }

        EquipParam.init(this);
            util = SharePreferenceUtil.init(this, "SAVE_USER");
            List<Department> departments = SQLiteTools.queryDepartmentS();

            if(departments.size() == 0){
                JsonUtils.compleJson2(this,R.raw.userdata);
            }
            if(NetUtils.isOpenNetwork(this) && !"".equals(util.getId()) && !"".equals(util.getName())) {

                TaskParams params = new TaskParams();
                params.put("username", util.getName());
                params.put("password", util.getPasswd());
                new LoginTask(this).execute(params);

        }

//        else if(NetUtils.isOpenNetwork(this))
//        ECHandlerHelper.postDelayedRunnOnUI(initRunnable, 3000);
//        else {
//            Intent intent = new Intent(WelComeActivity.this,MainActivity.class);
//            startActivity(intent);
//            finish();
//        }

//        SDKCoreHelper.getInstance().setLoginSuccess(new SDKCoreHelper.LoginSuccess() {
//            @Override
//            public void exec() {
//                Intent intent = new Intent(WelComeActivity.this, MainActivity.class);
//                startActivity(intent);
//                finish();
//            }
//        });




    }


    @Override
    public void success(int type, JSONObject jsonObject) {

        if(type == 100){
//            serviceVersion = jsonObject.optInt("version");
        }
    }


}